const express = require("express");
const router = express.Router();
const UserController = require("../controller/userController");
const UserValidator = require("../middleware/validator/userValidator");
const { uploadImg } = require("../utils/upload");
const { verifyToken, transferToken } = require("../utils/jwt");
/**
 * @route POST /register
 * @group Users - 用户相关操作
 * @returns {Array.<User>} 200 - 用户注册
 * @returns {Error}  default - 意外错误
 * @security JWT
 */
router.post("/register", UserValidator.register, UserController.register); // 用户注册
router.post("/login", UserValidator.login, UserController.login); // 用户登录
router.get("/:id", transferToken, UserController.getById); // 根据 ID 获取用户
router.post(
  "/updateAvatar",
  verifyToken,
  uploadImg.single("avatar"),
  UserController.updateAvatar
); // 更新头像
router.put("/", verifyToken, UserValidator.update, UserController.update); // 修改用户信息
router.get("/subscribe/:subscribeId", verifyToken, UserController.subscribe); // 关注频道
router.get(
  "/unsubscribe/:subscribeId",
  verifyToken,
  UserController.unsubscribe
); // 取消关注频道
router.get(
  "/getSubscribers/:userId",
  verifyToken,
  UserController.getSubscribers
); // 用户所有的订阅者
router.get("/getChannels/:userId", verifyToken, UserController.getChannels); // 用户所有的关注着

module.exports = router;
